package heuristics;

import java.util.LinkedList;
import java.util.List;

import Entities.Calendar;
import Entities.Course;


public class LazyStudentHeuristic implements IHeuristic  {
	final static int maxCoursesToTake = 6;	
	final static double workLoadFactor = 0.8;
	final static double averageGradeFactor = 0.2;
	final static double substractingAdjacentFactor = 0.1;
	
	@Override
	public double evaluate(Calendar toEvaluate) {
		double heuristicValue = 0;
		int numberOfCollisions = 0;
		// input check
		if (toEvaluate == null){
			throw new IllegalArgumentException("Illegal calendar to evaluate");
		}
		List<Course> courses = new LinkedList<Course>(toEvaluate.getCourses());
		// check if calendar is empty or calendar has collisions
		if (!toEvaluate.isEmpty()) // else 0 will returned
		{ 
			numberOfCollisions = toEvaluate.getNumberOfCollisions();
			if (numberOfCollisions > 0){
				heuristicValue = (-1)* numberOfCollisions;
			}
			else{	// calendar without collisions
				int numberOfCourses = courses.size(); 
				if (numberOfCourses > maxCoursesToTake){
					heuristicValue -= numberOfCourses; 
				}
				
				List<Course> coursesWithoutAdjacents = toEvaluate.getCoursesWithoutAdjacents();
				courses.removeAll(coursesWithoutAdjacents);
				
				// adding course load and grade factors
				for (Course course : courses) {
					if (course.getWorkLoad() < Calendar.getAverageWorkload()){
						heuristicValue += workLoadFactor*(Course.MaxWorkLoad - course.getWorkLoad());				
					}
					heuristicValue += averageGradeFactor*(course.getAverageGrade()*averageGradeNormalizationFactor);
				}
			}
		}
		return heuristicValue;
	}

	public int getMaxNumberOfCourses() {
		return maxCoursesToTake;
	}

	public String toString() {
		return "Lazy Student Heuristic";
	}
}
